package com.cleaningcloud.cld.mapper;

import com.cleaningcloud.cld.domain.CldRestbreaksCalendarMember;
import com.cleaningcloud.cld.domain.dto.CldRestbreaksCalendarMemberDto;
import com.cleaningcloud.cld.domain.vo.CldRestbreaksCalendarMemberVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 排休成员Mapper接口
 *
 * @author cleaningcloud
 * @date 2024-11-08
 */
public interface CldRestbreaksCalendarMemberMapper {
    /**
     * 查询排休成员
     *
     * @param restbreaksCalendarMemberId 排休成员主键
     * @return 排休成员
     */
    CldRestbreaksCalendarMemberVo selectCldRestbreaksCalendarMemberByRestbreaksCalendarMemberId(Long restbreaksCalendarMemberId);

    /**
     * 查询排休成员列表
     *
     * @param cldRestbreaksCalendarMember 排休成员
     * @return 排休成员集合
     */
    List<CldRestbreaksCalendarMemberVo> selectCldRestbreaksCalendarMemberList(CldRestbreaksCalendarMemberDto cldRestbreaksCalendarMember);

    /**
     * 新增排休成员
     *
     * @param cldRestbreaksCalendarMember 排休成员
     * @return 结果
     */
    int insertCldRestbreaksCalendarMember(CldRestbreaksCalendarMember cldRestbreaksCalendarMember);

    /**
     * 修改排休成员
     *
     * @param cldRestbreaksCalendarMember 排休成员
     * @return 结果
     */
    int updateCldRestbreaksCalendarMember(CldRestbreaksCalendarMember cldRestbreaksCalendarMember);

    /**
     * 删除排休成员
     *
     * @param restbreaksCalendarMemberId 排休成员主键
     * @return 结果
     */
    int deleteCldRestbreaksCalendarMemberByRestbreaksCalendarMemberId(Long restbreaksCalendarMemberId);

    /**
     * 批量删除排休成员
     *
     * @param restbreaksCalendarMemberIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteCldRestbreaksCalendarMemberByRestbreaksCalendarMemberIds(Long[] restbreaksCalendarMemberIds);


    /**
     * 批量新增排休人员
     *
     * @param list
     */
    void batchInsertRestbreaksCalendarStaff(@Param("list") List<CldRestbreaksCalendarMemberDto> list);


    /**
     * 根据人员删除排休记录
     *
     * @param staffId
     */
    @Delete("DELETE FROM cld_restbreaks_calendar_member WHERE project_staff_id = #{staffId}")
    void deleteByStaffId(@Param("staffId") Long staffId);


    /**
     * 查询该人员当月已排休次数
     *
     * @param staffId
     * @param restbreaksId
     * @return
     */
    @Select("select count(1) from cld_restbreaks_calendar_member where project_staff_id = #{staffId} and restbreaks_id = #{restbreaksId}")
    int selectCountByStaffIdAndRestbreaksId(@Param("staffId") Long staffId, @Param("restbreaksId") Long restbreaksId);

    /**
     * 判断当月当人当天是否已排休
     *
     * @param staffId
     * @param restbreaksId
     * @param restbreaksCalendarId
     * @return
     */
    @Select("select count(1) from cld_restbreaks_calendar_member where project_staff_id = #{staffId} and restbreaks_id = #{restbreaksId} and restbreaks_calendar_id = #{restbreaksCalendarId}")
    int selectCountByStaffIdAndRestbreaksIdAndDate(@Param("staffId") Long staffId, @Param("restbreaksId") Long restbreaksId, @Param("restbreaksCalendarId") Long restbreaksCalendarId);

    /**
     * 根据日历id批量删除排休人员
     *
     * @param calendarId
     */
    @Delete("delete from cld_restbreaks_calendar_member where restbreaks_id = #{restbreakId} and restbreaks_calendar_id = #{calendarId}")
    void batchDeleteByCalendarIdAndRestbreakId(@Param("calendarId") Long calendarId, @Param("restbreakId") Long restbreakId);


    /**
     * 根据日历id和小组ID批量删除排休人员
     *
     * @param calendarId
     */
    @Delete("delete from cld_restbreaks_calendar_member where restbreaks_id = #{restbreakId} and restbreaks_calendar_id = #{calendarId} and project_group_id = #{projectGroupId}")
    void batchDeleteByCalendarIdAndGroupIdAndRestbreakId(@Param("calendarId") Long calendarId, @Param("restbreakId") Long restbreakId, @Param("projectGroupId") Long projectGroupId);
}
